package oad.a233.v1.control;
import java.util.List;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public abstract class OADCapForm extends ViewGroup {

	protected Context _Context;
	protected AttributeSet _Attrs;
	
	protected int _ViewHeight =30;
	public void set_ViewHeight(int _ViewHeight) {
		this._ViewHeight = _ViewHeight;
	}
	

	private int _TitleLayout = R.layout.titlelv_bar_title_opal;	
	public int get_TitleLayout() {
		return _TitleLayout;
	}	
	public void set_TitleLayout(int _TitleLayout) {
		this._TitleLayout = _TitleLayout;
	}
	
	
	private RelativeLayout _TitleView;
	
	private int _Mode =2;

	public OADCapForm(Context context, AttributeSet attrs) {
		
		super(context, attrs);
		// TODO Auto-generated constructor stub
		_Context = context;
		_Attrs = attrs;
		
		
		
		TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.oadcapform);
		_Mode = a.getInteger(R.styleable.oadcapform_FormMode, 2);	

		
		a.recycle();
		
	
		InitView();
		
	}
	
	private void SetListData()
	{
		
	}
	
	/**
	 * 1 ListView
	 * 2 InfoVIew
	 */
	public void ChangeMode(int mode)
	{
		_Mode = mode;
	}

	@Override
	protected void onLayout(boolean c, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		l=this.getPaddingLeft();
		r= _TitleView.getMeasuredWidth()+this.getPaddingRight();
		t= this.getPaddingTop();		
		b= _ViewHeight + this.getPaddingBottom();		
		
	   _TitleView.layout(l, t, r, b);
	   
	   t+=_ViewHeight;
	   
	   capLayout(c,l,t,r,b);
	   
	}	
	
	private void InitView()
	{	
		try
		{			
			_TitleView = (RelativeLayout) OADCapForm.inflate(_Context,_TitleLayout,null);
			
			this.addView(_TitleView); 
			
		}
		catch(Exception e)
		{
			Log.e("InitView", e.getMessage());
		}	    
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		
		super.onDraw(canvas);
		_TitleView.draw(canvas);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
	
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		try
		{			 
			
			heightMeasureSpec = MeasureSpec.makeMeasureSpec(_ViewHeight, MeasureSpec.EXACTLY);		
			
			_TitleView.measure(widthMeasureSpec, heightMeasureSpec);
		
			
		}
		catch(Exception e)
		{
			Log.e("onMeasure", e.getMessage());
		}	
		
	}
	
	public void ChangeTitleLayOut(int layOutId)
	{
		_TitleView = (RelativeLayout) OADCapForm.inflate(_Context,layOutId,null);	
		
	}
	
	public void SetTitle(String title)
	{
		TextView tv = (TextView) _TitleView.findViewById(R.id.oad_title_name);
		
		tv.setText(title);
	}
	
	abstract void capLayout(boolean c, int l, int t, int r, int b);

}
